import {
  createWebHistory,
  createRouter,
  createWebHashHistory,
} from "vue-router";

import BasicLayout from "@/layouts/BasicLayout.vue";

export const constantRoutes = [
  {
    path: "/",
    name: "Index",
    component: BasicLayout,
    meta: { title: "首页" },
    redirect: "/situation",
    children: [
      {
        path: "/situation",
        name: "Situation",
        meta: { title: "综合态势", permission: "situation" },
        component: () => import("@/views/situation/index"),
      },

      {
        path: "/safety",
        name: "Safety",
        meta: { title: "安全监测", permission: "safety" },
        component: () => import("@/views/safety/index"),
        children: [
          {
            path: "warn",
            name: "warn",
            meta: { title: "预警总览", permission: "safety", safetySelect: true, nocache: true },
            component: () => import("@/views/safety/warn/index"),
          },
          {
            path: "sar",
            name: "sar",
            meta: { title: "卫星普查", permission: "safety", safetySelect: true, nocache: true },
            component: () => import("@/views/safety/sar/index"),
          },
          {
            path: "uav",
            name: "uav",
            meta: { title: "无人机详查", permission: "safety", safetySelect: true, nocache: true },
            component: () => import("@/views/safety/uav/index"),
          },
          {
            path: "iot",
            name: "iot",
            meta: { title: "地面巡查", permission: "safety", safetySelect: true, nocache: true },
            component: () => import("@/views/safety/iot/index"),
          }
        ]
      },
      {
        path: "/reserves",
        name: "Reserves",
        meta: { title: "储量管理", permission: "reserves" },
        component: () => import("@/views/reserves/index"),
      },

      {
        path: "/ecology",
        name: "Ecology",
        meta: { title: "生态环境", permission: "ecology" },
        component: () => import("@/views/ecology/index"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login"),
    meta: { title: "登录" },
  },
  {
    path: "/login-sso",
    name: "LoginSso",
    component: () => import("@/views/login-sso"),
    meta: { title: "正在登录" },
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error-page/page404"),
    hidden: true,
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

export default router;
